package hocusPocus.IHM;

import hocusPocus.Controllers.ControllerEcranAccueil;
import hocusPocus.Partie.Jeu;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;


/**
 * Affichage de la fenetre d'acceuil au demarrage
 *
 */
public class EcranAccueil extends JFrame {
	private Jeu jeu;
	private static EcranAccueil _instance = null;
	public JMenuItem mntmNouvellePartie;
	public JMenuBar menuBar;
	public JMenu mnPartie;
	public JMenuItem mntmQuitter;
	public JMenu mnAide;
	public JMenuItem mntmRgleDuJeu;
	public JMenu menu;
	public JMenuItem mntmAPropos;
	public JPanel contentPane;

	private EcranAccueil() {
		this.jeu = Jeu.getInstance();	
		lancerIHM();
	}

	public static EcranAccueil getInstance(){
		if(_instance == null) 
			_instance = new EcranAccueil();
		return _instance;
	}

	/**
	 * Creation de la fenetre principale avec la
	 * barre de menu
	 */
	public void lancerIHM() {
		int width = Toolkit.getDefaultToolkit().getScreenSize().width; 
		int heigh = Toolkit.getDefaultToolkit().getScreenSize().height; 
		ControllerEcranAccueil controle = new ControllerEcranAccueil(this);
		
		setIconImage(new ImageIcon(this.getClass().getResource("/images/icone.gif")).getImage());
		setResizable(false);
		setBackground(Color.WHITE);
		setTitle("Hocus Pocus");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		setSize(width, heigh);
		setLocation(0, 0);
		menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		mnPartie = new JMenu("Partie");
		menuBar.add(mnPartie);

		mntmNouvellePartie = new JMenuItem("Nouvelle Partie");
		mnPartie.add(mntmNouvellePartie);
		mntmNouvellePartie.addActionListener(controle);

		mntmQuitter = new JMenuItem("Quitter");
		mntmQuitter.addActionListener(controle);
		mnPartie.add(mntmQuitter);

		mnAide = new JMenu("Aide");
		menuBar.add(mnAide);

		mntmRgleDuJeu = new JMenuItem("Regles du jeu");
		mntmRgleDuJeu.addActionListener(controle);

		mnAide.add(mntmRgleDuJeu);

		menu = new JMenu("?");
		menuBar.add(menu);

		mntmAPropos = new JMenuItem("A Propos");
		mntmAPropos.addActionListener(controle);
		menu.add(mntmAPropos);

		contentPane = new JPanel();
		contentPane.setBackground(Color.YELLOW);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));

		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setIcon(new ImageIcon(EcranAccueil.class.getResource("/images/BoiteDuJeu.gif")));
		contentPane.add(lblNewLabel, BorderLayout.WEST);

		JLabel lblNewLabel_1 = new JLabel("");
		lblNewLabel_1.setIcon(new ImageIcon(EcranAccueil.class.getResource("/images/carte.gif")));
		contentPane.add(lblNewLabel_1, BorderLayout.EAST);
		this.setVisible(true);
	}
}


